﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using VisionCloud.Utility;
using static VisionCloud.Core.Model.Ms.TaskPoints;

namespace VisionCloud.Domain.DtoModel.Ms
{
    public class SubPointInfo
    {
        /// <summary>
        /// ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 编号
        /// </summary>
        public string Index { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string Status { get; set; }

        /// <summary>
        /// 过程状态包括进度信息
        /// </summary>
        //[JsonIgnore]
        public string StatusStr
        {
            get
            {
                return this.Status;
            }
        }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }
    }

    public class TaskPointDto
    {
        public Guid pointId { get; set; }
        public Guid taskId { get; set; }

        public int pointIndex { get; set; }
        public string x { get; set; }
        public string y { get; set; }
        public string offsetX { get; set; }
        public string offsetY { get; set; }

        public PointStatus status { get; set; }

        public string PointStatusStr
        {
            get
            {
                return this.status.ToString();
            }
        }

        public string filePath { get; set; }
        public RateStatus rateValue { get; set; }

        public bool rate
        {
            get
            {
                if (rateValue == RateStatus.低)
                    return false;
                if (rateValue == RateStatus.高)
                    return true;
                return false;
            }
        }

        public string ErrorMessage { get; set; }

        /// <summary>
        /// 站点测量项
        /// </summary>
        public UseStandard UseStandards { get; set; }

        /// <summary>
        /// 测量项
        /// </summary>
        public List<MeasureItem> MeasureItems { get; set; } = new List<MeasureItem>();

        /// <summary>
        /// 站点类型ID
        /// </summary>
        public Guid MsPointTypeId { get; set; }

        /// <summary>
        /// 站点类型
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// 站点类型名称
        /// </summary>
        public string MsPointTypeName { get; set; }

        /// <summary>
        /// 是否完成人工测量项录入
        /// </summary>
        public bool IsManualMeasureInput { get; set; }

        /// <summary>
        /// 是否正在测量
        /// </summary>
        public bool IsMeasuring { get; set; }

        /// <summary>
        /// 是否更新新录入实测值（用于记录前端是否修改了实际测量项数据）
        /// </summary>
        public bool IsManualMeasureInputUpdate { get; set; }

        public TaskPointDto()
        {
            this.IsManualMeasureInputUpdate = false;
        }

        /// <summary>
        /// 子站点信息列表
        /// </summary>
        public string SubPointList
        {
            get; set;
        }

        private SubPointInfo[] _SubPointArray;

        public SubPointInfo[] SubPointArray
        {
            get
            {
                try
                {
                    _SubPointArray = Array.Empty<SubPointInfo>();
                    if (!string.IsNullOrWhiteSpace(SubPointList))
                    {
                        _SubPointArray = JsonConvert.DeserializeObject<SubPointInfo[]>(SubPointList);
                        if (_SubPointArray == null)
                        {
                            _SubPointArray = Array.Empty<SubPointInfo>();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Info($"子站点序列化有误，错误信息：{ex.Message}");
                    _SubPointArray = Array.Empty<SubPointInfo>();
                }
                return _SubPointArray;
            }
        }

        /// <summary>
        /// 人工测量项报告状态
        /// </summary>
        public string ManualReportStatusStr
        {
            get; set;
        }

        /// <summary>
        /// 人工测量项报告错误信息
        /// </summary>
        public string ManualReportErrMsg { get; set; }

        /// <summary>
        /// 户型名称
        /// </summary>
        public string HouseTypeName { get; set; }

        /// <summary>
        /// 户型Key
        /// </summary>
        public int? HouseTypeKey { get; set; }

        /// <summary>
        /// 测量站点数，爆点数
        /// </summary>
        public List<MeasureInfo> MeasureInfos { get; set; }
    }
}